import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.text.DateFormatter;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.SwingConstants;
import javax.swing.JTextField;


@SuppressWarnings("serial")
public class WeightEntryWindow extends JFrame {

	private JPanel contentPane;
	private JButton btnOk;
	private JButton btnCancel;
	private JTextField ftfDate;
	private JTextField ftfWeight;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					WeightEntryWindow frame = new WeightEntryWindow();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public WeightEntryWindow() {
		setTitle("ENTER WEIGHT");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JPanel panel_1 = new JPanel();
		contentPane.add(panel_1, BorderLayout.NORTH);
		
		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.SOUTH);
		
		btnOk = new JButton("OK");
		panel.add(btnOk);
		
		JButton btnCancel = new JButton("Cancel");
		panel.add(btnCancel);
		panel_1.setLayout(new GridLayout(0, 2, 0, 0));
		
		JLabel lblNewLabel = new JLabel("Date: ");
		lblNewLabel.setHorizontalAlignment(SwingConstants.TRAILING);
		panel_1.add(lblNewLabel);
		ftfDate = new JTextField();
		ftfDate.setColumns(10);
		ftfDate.setText(new Date().toString());
		panel_1.add(ftfDate);
		JLabel lblNewLabel_1 = new JLabel("Weight: ");
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.TRAILING);
		panel_1.add(lblNewLabel_1);
		
		ftfWeight = new JTextField();
		ftfWeight.setColumns(10);
		panel_1.add(ftfWeight);
		
		JLabel lblNewLabel_2 = new JLabel("Units: ");
		lblNewLabel_2.setHorizontalAlignment(SwingConstants.TRAILING);
		panel_1.add(lblNewLabel_2);
		
		JLabel lblNewLabel_3 = new JLabel("Pounds");
		panel_1.add(lblNewLabel_3);
		
		// Action for cancel
		btnCancel.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
			
		});
	}
	
	// add hook for view notification
	public void addNewWeightListener(ActionListener listener) {
		btnOk.addActionListener(listener);
	}
	
	public String getWeight() {
		return ftfWeight.getText();
	}
	
	public String getDate() {
		return ftfDate.getText();
	}

}
